'use strict';

/**
 * @name DemandSolCtrl
 * @description 需求查看解决方案列表
 * @author ZYF
 */

angular.module('metalabOperationApp').controller('DemandSolCtrl', ['$scope', 'params', 'MetaResources', 'MetaRemind', '$uibModalInstance', 'MetaUtils', 'MetaSearch', function($scope, params, MetaResources, MetaRemind, $uibModalInstance, MetaUtils, MetaSearch) {
    $scope.listCtrl = {
        searchConfig: {
            'sn_like': '编号',
            'title_like': '标题'
        },
        sortParams: '-created_at',
        searchParams: {},
        tableParams: {}
    };
    $scope.init = function() {
        //初始化搜索
        MetaSearch.initSearchModule($scope.listCtrl.searchParams, $scope.listCtrl.searchConfig, null, $scope.changeUrl);
        //初始化表格参数
        MetaUtils.initTableModule($scope.listCtrl.tableParams, null, $scope.changeUrl, true);
        //获取数据
        $scope.getListData(1);
    };
    $scope.getListData = function(page) {
        var queryParams = {
            'demand_id': params.data.id,
            '_embed': 'technology, technology.publisher',
            '_sort': '',
            '_range': ''
        };
        var dynamicQueryParams = [];
        var urlParams = {'search': '','value': '','type': 'model'};
        MetaSearch.encodeUrlSearchParams(urlParams, $scope.listCtrl.searchParams);
        MetaUtils.buildQueryParams(page, queryParams, dynamicQueryParams, $scope.listCtrl, urlParams);
        MetaResources.demand.queryNum(
            queryParams,
            function(data, header) {
                MetaUtils.receiveListData($scope.listCtrl, null, page, data, header);
            },
            function(error) {
                MetaRemind.serverError(error);
            });
    };
    $scope.cancel = function() {
        $uibModalInstance.dismiss('cancel');
    };
    $scope.changeUrl = function() {
        $scope.getListData($scope.listCtrl.tableParams.currentPage);
    };
    $scope.init();
}]);
